package com.bj.util.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

public class SpringLocator implements BeanFactoryAware {
    private static BeanFactory beanFactory = null;

    public void setBeanFactory(BeanFactory factory) throws BeansException {
        beanFactory = factory;
    }

    public static <T> T getBean(String beanName) {
        if (beanFactory != null) {
            return (T)beanFactory.getBean(beanName);
        }
        return null;
    }

    public static <T> T getDao(String daoName) {
        return (T)getBean(daoName);
    }

    public static <T> T getService(String serviceName) {
        return (T)getBean(serviceName);
    }
}
